Crate crypto_primes
source ·Expand description
Prime number tools for crypto-bigint
This library implements prime number generation and primality checking for crypto-bigint
integers.
In particular:
- Generating random primes and safe primes of given bit size;
- Sieving iterator;
- Miller-Rabin test;
- Strong and extra strong Lucas tests, and Lucas-V test.
See the documentation for the specific tests for more information and references.
Modules
- Components to build your own primality test. Handle with care.
Traits
- Provides a generic way to access methods for random prime number generation and primality checking, wrapping the standalone functions (
is_prime_with_rng
etc).
Functions
- generate_prime
default-rng
Returns a random prime of sizebit_length
usingOsRng
as the RNG. Ifbit_length
isNone
, the full size ofUint<L>
is used. - Returns a random prime of size
bit_length
using the provided RNG. Ifbit_length
isNone
, the full size ofUint<L>
is used. - generate_safe_prime
default-rng
Returns a random safe prime (that is, such that(n - 1) / 2
is also prime) of sizebit_length
usingOsRng
as the RNG. Ifbit_length
isNone
, the full size ofUint<L>
is used. - Returns a random safe prime (that is, such that
(n - 1) / 2
is also prime) of sizebit_length
using the provided RNG. Ifbit_length
isNone
, the full size ofUint<L>
is used. - is_prime
default-rng
Checks probabilistically if the given number is prime usingOsRng
as the RNG. - Checks probabilistically if the given number is prime using the provided RNG.
- is_safe_prime
default-rng
Checks probabilistically if the given number is a safe prime (that is, such that(n - 1) / 2
is also prime) usingOsRng
as the RNG. - Checks probabilistically if the given number is a safe prime using the provided RNG.